package customs;

import java.awt.Color;
import java.awt.Component;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/*
 * USAGE:
 * 
 * tableIndex.getColumnModel().getColumn(0).setCellRenderer(new ColorCellRenderer(tableIndex.getValueAt(9, 0).toString()));
 */

@SuppressWarnings("serial")
public class ColorCellRenderer extends DefaultTableCellRenderer {

	List<String> list = null;
	List<String> indexesOut = null;
	public ColorCellRenderer() {
		super();
	}

	
	public ColorCellRenderer(List<String> list22, List<String> indexesOut) {
		list = list22;
		this.indexesOut = indexesOut;
		
	}


	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		final JLabel cellComponent = (JLabel) super
				.getTableCellRendererComponent(table, value, isSelected,
						hasFocus, row, column);
			
		Object val = table.getValueAt(row, 0);
		
		
		if(list.contains(val))
		{
			cellComponent.setBackground(Color.BLUE);
			cellComponent.setForeground(Color.WHITE);
		}
		else
		{	
			if (indexesOut.contains(val))
			{
				cellComponent.setBackground(Color.RED);
				cellComponent.setForeground(Color.WHITE);
			}
			else
			{
			cellComponent.setBackground(Color.WHITE);
			cellComponent.setForeground(Color.BLACK);
			}
		
		}

	
		
			
		return super.getTableCellRendererComponent(table, value, isSelected,
				hasFocus, row, column);
	}
	

}
